#include "DockableWindow.h"

#include "DockWidgetTitleBar.h"

#include "Asset/EngineDefaultPackage.h"

#include "Widgets/Editor/DragWindowArea.h"
#include "Widgets/Editor/WindowButtons.h"
#include "Widgets/Editor/WindowResizeble.h"

#include "DockLayout.h"

RDockableWindow::RDockableWindow()
{
    const float MenuBarHeight=25.f;

    auto Dragable= NewWidget<RMouseDragWindowArea>(GetRootWidget());
    Dragable->Anchor.HorizontalFill(GetRootWidget());
    Dragable->Height=MenuBarHeight;

    auto Icon=NewWidget<RImageWidget>(GetRootWidget());
    Icon->Image=REngineDefaultPackage::Get()->GetEngineIcon();
    Icon->Width=MenuBarHeight;
    Icon->Height=MenuBarHeight;

    auto Buttons=NewWidget<RWindowButtons>(GetRootWidget());
    Buttons->Anchor.RightReference=GetRootWidget();

    //resizable 
    auto Resizable= NewWidget<RWindowResizeble>(GetRootWidget());
    Resizable->Anchor.Fill(GetRootWidget());

    ParentOfRootLayout=NewWidget<RWidget>(GetRootWidget());
    ParentOfRootLayout->Anchor.Fill(GetRootWidget());

    RootLayout=NewWidget<RDockLayout>(ParentOfRootLayout);
    RootLayout->Anchor.Fill(ParentOfRootLayout);
}

RWidgetPtr RDockableWindow::GetParentOfRootLayout()
{
    return ParentOfRootLayout;
}

void RDockableWindow::SetRootLayout(TSharedObjectPtr<RDockLayout> InRootLayout)
{
    if(RootLayout)
    {
        ParentOfRootLayout->RemoveSubWidget(RootLayout);
    }

    ParentOfRootLayout->AddSubWidget(InRootLayout);
    InRootLayout->Anchor.Fill(ParentOfRootLayout);

    RootLayout=InRootLayout;
}

TSharedObjectPtr<RDockLayout> RDockableWindow::GetRootLayout()
{
    return RootLayout;
}
